<?php #coding: utf-8 æ ø å
class Rediger extends CI_Controller {

	function birth()
	{
	
		$type = $this->uri->segment(4,0); 
		$data['type'] = $type;
		
	
		$id = $this->uri->segment(5,0); 
		$alder = 50; //alder bliver ikke brugt endnu - men skal være defineret som halvtreds for at det virker (god kode).
		$aar = $this->input->post('aar');
		$maaned = $this->input->post('maaned');
		$dag = $this->input->post('dag');
		$this->load->model('core/element');
		$this->load->model('translation/tid_model');
		$dato = $this->tid_model->til_db($alder, $aar, $maaned, $dag);
		$this->element->set_birth($id, $dato);
		$data['besked'] = "Dato opdateret.";
			
			
		redirect("almanak/side/".$id);			
		
	}
	
	
	function death()
	{
	
		$type = $this->uri->segment(4,0); 
		$data['type'] = $type;
		

		$id = $this->uri->segment(5,0); 
		$alder = 50; //alder bliver ikke brugt endnu - men skal være defineret som halvtreds for at det virker (god kode).
		$aar = $this->input->post('aar');
		$maaned = $this->input->post('maaned');
		$dag = $this->input->post('dag');
		$this->load->model('core/element');
		$this->load->model('translation/tid_model');
		$dato = $this->tid_model->til_db($alder, $aar, $maaned, $dag);
		$this->element->set_death($id, $dato);
		$data['besked'] = "Dato opdateret.";
			


		redirect("almanak/side/".$id);	

/*
		else
		{
			$id = $this->uri->segment(5,0);
			$id = (int) $id;
			//echo gettype($id);
		}
		$this->load->model('all/vis_model');
		$this->load->model('all/tid');	
		$data['stamdata'] = $this->vis_model->stamdata($type, $id);
		$data['datoarray'] = $this->tid->tid_dato($data['stamdata']['death']);
		$indhold[] = 'all/death';	
		$data['main_content'] = $indhold;
		$this->load->view('template', $data);*/
	}
	
	function eksisterende()
	{
		
		//henter deltager information ud fra brugernavnet fra session
		$username = $this->session->userdata('username'); 
		$data['username']=$username;
		$this->load->model('login_model');
		$data['deltager'] = $this->login_model->get_deltager_data($username);
		$userid = $data['deltager']['id'];
		
		//HENTER INGAMEOPLYSNINGER XXX SKAL MÅSKE LÆGGES I SESSIONEN.
		$ingame = $this->session->userdata('ingame'); 
		$ingame_id = (int) $ingame['ingame_id'];
		$data['ingame'] = $ingame;

		

		$type = $this->uri->segment(4,0);
		$data['type'] = $type;
		//echo "<br>type er ".$type."<br>";
		$id = $this->uri->segment(5,0);
		
		$this->load->model('all/vis_model');
		$this->load->model('all/tid');
		
		if(isset($_POST['aktion'])) //tjekker om siden hentes med oplysninger om noget der skal ændres
		{
			$aktion = $this->input->post('aktion'); 	
		}
		else
		{
			$aktion = "ingenting";	
		}
		//echo "aktion er ".$aktion."<br><br>";

		if($type == "beskrivelse")
		{
			
			$data['beskrivelse'] = $this->vis_model->beskrivelse($id);
			//echo "<br>data[beskrivelse] er: <br>"; print_r($data['beskrivelse']); echo "<br>";
			$data['datoarray'] = $this->tid->tid_dato($data['beskrivelse']['dato']); //bruges til tids-viewet
			$data['omhandler'] = $this->vis_model->stamdata($data['beskrivelse']['omhandler'], $data['beskrivelse']['omhandler_id']);
		
			if($aktion == "ret") //ret beskrivelse
			{
				$this->load->model('all/rediger_model');
				
				$overskrift = $this->input->post('ny_overskrift');
				
				$beskrivelse = $this->input->post('ny_beskrivelse');
				$alder = $this->input->post('alder');
				$alder = str_pad($alder,2,0,STR_PAD_LEFT); 
				//echo "alder er ".$alder."<br>";
				$aar = $this->input->post('aar');
	
				$aar = str_pad($aar,4,0,STR_PAD_LEFT); 
				//echo "aar er ".$aar."<br>";
				$maaned = $this->input->post('maaned');
				$maaned = str_pad($maaned,2,0,STR_PAD_LEFT); 
				//echo "maaned er ".$maaned."<br>";
				$dag = $this->input->post('dag');
				$dag = str_pad($dag,2,0,STR_PAD_LEFT); 
				//echo "dag er ".$dag."<br>";
				$dato = $alder.$aar.$maaned.$dag;
				//echo "dato er ".$dato."<br>";
				$id_beskrivelse = $id;	
				$karakter_id = $this->input->post('karakter_id'); //skal bruges ved ændring fra off_game til in_game
				$inoffgame = $this->input->post('inoffgame');
				$hemmelig = $this->input->post('hemmelig');
				$data['kommentar'] = "Melder: Beskrivelse opdateret";
				$this->rediger_model->beskrivelse($id_beskrivelse,$overskrift,$beskrivelse, $dato,$inoffgame, $hemmelig, $karakter_id);
				$data['beskrivelse'] = $this->vis_model->beskrivelse($id); //henter beskrivelsen ind igen efter at den er blevet opdateret
				//echo "controlleren siger: redigeret!";
			}
			elseif($aktion == "slet") //slet beskrivelse
			{
				echo $id_beskrivelse = $this->input->post('id_beskrivelse');
				$this->load->model('all/slet_model');
				$this->slet_model->beskrivelse($id_beskrivelse);
				
				if($type == "beskrivelse")
				{
					redirect('all/vis/se/'.$data['beskrivelse']['omhandler'].'/'.$data['beskrivelse']['omhandler_id']);	
				}
				else
				{
					redirect('all/vis/se/'.$type.'/'.$id);
				}
				
	
			}
			
			$data['stamdata'] = $this->vis_model->stamdata("entitet", $ingame_id);
			//print_r($data['stamdata']);
							
			$indhold[] = 'all/rediger_beskrivelse';


		}
		
		$data['main_content'] = $indhold;
		$this->load->view('template', $data);
		
	}
	
	function normalrelationer_over()
	{
		$type = $this->uri->segment(4,0);
		//echo "<br>Rediger controlleren: type er ".$type."<br>";
		$data['type'] = $type;
		$id = $this->uri->segment(5,0);
		$id = (int) $id;
		
		
		
		if(!isset($id) || $id == 0){
			if(isset($_POST['id'])) 
			{
				$id = $this->input->post('id');
			}
			else //altså, hvis man kommer til siden direkte
			{
				echo "fejl - id ikke sat i rediger controlleren";
			}
		}
		
		
		
		if(isset($_POST['aktion']))
		{
			$aktion = $this->input->post('aktion'); //fx slet
		}
		else
		{
			$aktion = "ingenting";
		}
		
		if($aktion == "slet")
		{
			
			$under_id = $id;
			$over_id = $this->input->post('id_over');
			$this->load->model('all/slet_model');
			$this->slet_model->relation($type, $under_id, $over_id, "normal");
		}
		if($aktion == "opret")
		{
			$under_id = $id;
			//echo "<br> under_id er ".$under_id."<br>";
			$over_id = $this->input->post('id_over');
			//echo "<br> over_id er ".$over_id."<br>";
			//echo "<br> type er ".$type."<br>";
			$this->load->model('all/opret_model');
			$this->opret_model->relation($type, $under_id, $over_id, "normal");
		}

		$this->load->database();
		
		$this->load->model('all/vis_model');
		
		
		if($type == "begivenhed"){ $data['list_alle'] = $this->vis_model->alle("begivenhed"); }
		elseif($type == "entitet"){ $data['list_alle'] = $this->vis_model->alle("gruppe"); }
		elseif($type == "sted"){ $data['list_alle'] = $this->vis_model->alle("sted"); }
		//echo "<br> Rediger controller: list_alle er <br>"; print_r($data['list_alle']); echo "<br>";
		
		$data['stamdata'] = $this->vis_model->stamdata($type, $id);
		//echo "<br>Rediger controlleren: data[stamdata] er<br>"; print_r($data['stamdata']); echo "<br>";
		$data['kommando'] = "grupperelationer";
		
		$indhold = array();
		$indhold[] = 'all/rediger_normalrelationer';

		$data['main_content'] = $indhold;
		$this->load->view('template', $data);
	}
	
	function profession()
	{
	
		$id = $this->uri->segment(4,0);
		$id = (int) $id;
				
	
			$profession_id = $this->input->post('profession_id');
			//echo "<br>rediger controlleren: profession_id er ".$profession_id."<br>";
			$this->load->model('core/rediger_model');
			$this->rediger_model->profession($id, $profession_id);
			$data['besked'] = "profession updateret";

		redirect("core/vis/se/entitet/".$id);
	}
	


	function familie()
	{
		//HENTER DELTAGEROPLSYNINGER
		$username = $this->session->userdata('username'); 
		$data['username']=$username;
		$this->load->model('login_model');
		$data['deltager'] = $this->login_model->get_deltager_data($username);
		$userid = $data['deltager']['id'];
		
		
		//HENTER INGAMEOPLYSNINGER XXX SKAL MÅSKE LÆGGES I SESSIONEN.
		$ingame = $this->session->userdata('ingame'); 
		$ingame_id = (int) $ingame['ingame_id'];
		$data['ingame'] = $ingame;
	
		$this->load->model('core/vis_model');
		$this->load->model('core/individ');
		
		$aktion = $this->input->post('aktion');

		$i = new individ();
	
		if($aktion == "tilfoej_eksisterende_foraeldre")
		{
			
			$id = $this->input->post('under_id');
			$over_id = $this->input->post('over_id');
			//sletter eksisterende forældrerrelationer
			$i->slet_relation($id, $over_id, "familie");
			$this->individ->ny_familie_relation($over_id, $id);
		}
		elseif($aktion == "tilfoej_ny_foraeldre")
		{
			$deltager = $this->session->userdata('deltager');
			$id = $this->input->post('under_id');	
			$nyt_navn = $this->input->post('nyt_navn');
			$i->find_race($id);
			$id_race = $i->race_id;
			$this->load->model('core/opret_model');
			$nyt_id = $this->opret_model->individ($nyt_navn,0,0,NULL, NULL,$id_race,$deltager['userid'],$id_race);
			$i->set_race($nyt_id, $id_race);
			$this->individ->ny_familie_relation($nyt_id, $id);

		}
		elseif($aktion == "slet_foraeldre")
		{
			$id = $this->input->post('id');
			$over_id = $this->input->post('over_id');
			$this->load->model('core/element');
			$this->element->slet_relation($id, $over_id, "familie");
		}
		elseif($aktion == "tilfoej_eksisterende_barn")
		{
			$id = $this->input->post('over_id');
			$under_id = $this->input->post('under_id');
			$i->slet_relation($under_id, $id, "familie");
			$besked = $this->individ->ny_familie_relation($id, $under_id);
			
		}
		elseif($aktion == "tilfoej_nyt_barn")
		{
			$deltager = $this->session->userdata('deltager');
			$id = $this->input->post('over_id');	
			$nyt_navn = $this->input->post('nyt_navn');
			$i = new individ();
			$i->find_race($id);
			$id_race = $i->race_id;
			$this->load->model('core/opret_model');
			$nyt_id = $this->opret_model->individ($nyt_navn,0,0,NULL,NULL,$id_race,$deltager['userid'],$id_race);
			$i->set_race($nyt_id, $id_race);
			$this->individ->ny_familie_relation($id, $nyt_id);
		}
		elseif($aktion == "slet_barn")
		{
			$id = $this->input->post('id');
			$under_id = $this->input->post('under_id');
			$this->load->model('core/element');
			$this->element->slet_relation($under_id, $id, "familie");
		}
		else
		{
			$id = $this->uri->segment(4);
			$id = (int) $id;
		}

		redirect('almanak/side/'.$id.'/rediger_familie');	

	}
	
	function race()
	{

		//$data['type'] = $type;
		$id = $this->uri->segment(4,0);
		$id = (int) $id;

		//$this->load->database();
		$this->load->model('core/individ');

		$ny_race = $this->input->post('race_id');
		$this->individ->set_race($id,$ny_race);

		
		redirect("almanak/side/".$id);
		
	}
	
	function koen()
	{
		
		//$type = "entitet";
		//$data['type'] = $type;
		
		//$data['id'] = $id;
		
		

		//$this->load->database();
		$this->load->model('core/individ');
		$id = $this->uri->segment(4,0);
		$id = (int) $id;	
		$nyt_koen = $this->input->post('nyt_koen');
		$this->individ->set_koen($id,$nyt_koen);
		

		redirect("almanak/side/".$id);
		
	}
	
	
	function navn()
	{
		$type = $this->uri->segment(4,0);
		$data['type'] = $type;
		$id = $this->uri->segment(5,0);

		
		$this->load->model('core/rediger_model');

		$nyt_navn = $this->input->post('nyt_navn'); 

		$this->rediger_model->navn($type, $id,$nyt_navn);
		
		redirect("almanak/side/".$id);


	}
	


    function slet_begivenhed_deltager(){

		$this->load->model('core/slet_model');
		$this->load->model('core/element');
		$this->load->model('translation/array_model');


	/*	$stam_id = $this->input->post('stam_id');
		$id_array = $this->input->post('deltager_array');
		$redirect = $this->input->post('redirect');

		$id_array = $this->array_model->post_ider_modtag($id_array);
		$this->load->model('core/slet_model');
		$this->load->model('core/element');
		$stam_id = (int) $this->uri->segment(4,0);
*/
		$deltager_array_string = $this->input->post("id_array");
		$begivenhed_id = $this->input->post("stam_id");
		$deltager_array = explode(",",$deltager_array_string);	
		echo $begivenhed_id.br();
		print_r($deltager_array);

		$element = new element();
		foreach($deltager_array as $r){

                $this->slet_model->begivenhed_entitet_sted("entitet", $begivenhed_id, $r);
		
		}
		
        
        redirect('almanak/side/'.$stam_id.'/rediger_deltagere');

    }

    function tilfoej_begivenhed_deltager(){


		$this->load->model('core/element');
		$this->load->model('translation/array_model');
        $this->load->model('core/tilfoej_model');

		$stam_id = $this->input->post('stam_id');
		$id_array = $this->input->post('deltager_array');
		$redirect = $this->input->post('redirect');
		$id_array = $this->array_model->post_ider_modtag($id_array);

		foreach($id_array as $r){
                $this->tilfoej_model->entitet_til_begivenhed($stam_id, $r);

		}

		redirect("almanak/side/".$stam_id."/rediger_deltagere");

    }

    function tilfoej_begivenhed_sted(){
		$this->load->model('core/element');
		$this->load->model('translation/array_model');
        $this->load->model('core/tilfoej_model');

		$stam_id = $this->input->post('stam_id');
		$id_array = $this->input->post('sted_array');
		$redirect = $this->input->post('redirect');
		$id_array = $this->array_model->post_ider_modtag($id_array);

		foreach($id_array as $r){
                $this->tilfoej_model->sted_til_begivenhed($stam_id, $r);

		}

		redirect("almanak/side/".$stam_id."/rediger_steder");

    }

    function slet_begivenhed_sted(){


		$this->load->model('core/element');
		$this->load->model('translation/array_model');
        $this->load->model('core/slet_model');

		$sted_array_string = $this->input->post("id_array");
		$begivenhed_id = $this->input->post("stam_id");
		$sted_array = explode(",",$sted_array_string);	
		echo $begivenhed_id.br();
		print_r($deltager_array);

		$element = new element();
		foreach($sted_array as $r){

                $this->slet_model->begivenhed_entitet_sted("sted", $begivenhed_id, $r);
		
		}
		
        
        redirect('almanak/side/'.$begivenhed_id.'/rediger_steder');


    }

    function tilfoej_historie(){
		echo "Tilføj historie";
		$this->load->model('core/element');
		$this->load->model('translation/array_model');
        $this->load->model('core/tilfoej_model');

		$stam_id = $this->input->post('stam_id');
		$id_array = $this->input->post('begivenhed_array');
		$redirect = $this->input->post('redirect');
		$id_array = explode(",",$id_array);	

		foreach($id_array as $r){
		
                $this->tilfoej_model->sted_til_begivenhed($r, $stam_id);
			
		}
		
		
		redirect("almanak/side/".$stam_id."/rediger_historie");

    }

    function slet_historie(){


		$this->load->model('core/element');
		$this->load->model('translation/array_model');
        $this->load->model('core/slet_model');

		$begivenhed_array_string = $this->input->post("id_array");
		$sted_id = $this->input->post("stam_id");
		$begivenhed_array = explode(",",$begivenhed_array_string);	
		echo $sted_id.br();
		print_r($begivenhed_array);

		$element = new element();
		foreach($begivenhed_array as $r){

                $this->slet_model->begivenhed_entitet_sted("sted", $r, $sted_id);
		
		}
		
        
        redirect('almanak/side/'.$sted_id.'/rediger_historie');

    }	


    function tilfoej_oplevelser(){
		$this->load->model('core/element');
		$this->load->model('translation/array_model');
        $this->load->model('core/tilfoej_model');

		$stam_id = $this->input->post('stam_id');
		$id_array = $this->input->post('id_array');
		print_r($id_array);
		$redirect = $this->input->post('redirect');
		$id_array = $this->array_model->post_ider_modtag($id_array);
		print_r($id_array);
		foreach($id_array as $r){
			//if($this->input->post('valgt_'.$r)=="on"){
                $this->tilfoej_model->entitet_til_begivenhed($r, $stam_id);
			//}
		}
		
		redirect($redirect);

    }

    function slet_oplevelser(){


		$this->load->model('core/element');
		$this->load->model('translation/array_model');
        $this->load->model('core/slet_model');

		$stam_id = $this->input->post('stam_id');
		$id_array = $this->input->post('id_array');
		$redirect = $this->input->post('redirect');
    	$id_array = $this->array_model->post_ider_modtag($id_array);

		foreach($id_array as $r){
			if($this->input->post('valgt_'.$r)=="on"){
                $this->slet_model->begivenhed_entitet_sted("entitet",$r, $stam_id);
			}
		}

    redirect('almanak/side/'.$stam_id.'/rediger_oplevelser');
    }












	function begivenhed_deltager()
	{
		$aktion = $this->uri->segment(4,0);	
		$id_begivenhed = $this->uri->segment(5,0);
		$id_entitet = $this->uri->segment(6,0);		
		$vinkel = $this->uri->segment(7,0);
		if($aktion == "tilfoej")
		{	
			$vinkel = $this->input->post('vinkel');
		}	

		if($vinkel == "begivenhed")
		{
			$id_begivenhed = $this->uri->segment(5,0);
			$id_entitet = $this->uri->segment(6,0);
		
			if($id_entitet == 0)
			{
			
				$id_entitet = $this->input->post('deltager_id'); 
			}
		}

		if($vinkel == "session")
		{
			$id_begivenhed = $this->uri->segment(5,0);
			$id_entitet = $this->uri->segment(6,0);
		
			if($id_entitet == 0)
			{
			
				$id_entitet = $this->input->post('deltager_id'); 
			}
		}



		if($vinkel == "entitet")
		{
			$id_begivenhed = $this->uri->segment(6,0);
			$id_entitet = $this->uri->segment(5,0);
		
			if($id_begivenhed == 0)
			{
			
				$id_begivenhed = $this->input->post('oplevelse_id'); 
			}
		}


		if($aktion == "tilfoej")
		{
			
			$this->load->model('core/tilfoej_model');
			$this->tilfoej_model->entitet_til_begivenhed($id_begivenhed, $id_entitet);

		}

		if($aktion == "slet")
		{
			$this->load->model('core/slet_model');
			$this->slet_model->begivenhed_entitet_sted("entitet", $id_begivenhed, $id_entitet);
		}

		if($vinkel == "begivenhed")
		{	
			redirect("core/vis/se/begivenhed/".$id_begivenhed."/rediger_deltagere");
		}

		if($vinkel == "session")
		{	
			
			$kampagne_id = $this->input->post('kampagne_id');
			if(empty($kampagne_id))
			{
				$kampagne_id = $this->uri->segment(8);
			}

			redirect("forord");
		}


		if($vinkel == "entitet")
		{	
			redirect("core/vis/se/individ/".$id_entitet."/rediger_oplevelser");
		}

	}
	
	
	function begivenhed_sted()
	{
	
	
		$id_begivenhed = $this->uri->segment(5,0);
		$aktion = $this->uri->segment(4,0);
		$id_sted = $this->uri->segment(6,0);
		$vinkel = $this->uri->segment(7,0);
		if($aktion == "tilfoej")
		{	
			$vinkel = $this->input->post('vinkel');
		}		


		if($id_sted == 0)
		{
			$id_sted = $this->input->post('sted_id'); 
		}
		//echo "id_begivenhed er ".$id_begivenhed."<br>";
		//echo "id_entitet er ".$id_entitet."<br>";
		if($vinkel == "sted")
		{
			$id_begivenhed = $this->uri->segment(6,0);
			$id_sted = $this->uri->segment(5,0);
		
			if($id_begivenhed == 0)
			{
			
				$id_begivenhed = $this->input->post('historie_id'); 
			}
		}


		if($vinkel == "begivenhed")
		{
			$id_begivenhed = $this->uri->segment(5,0);
			$id_sted = $this->uri->segment(6,0);
		
			if($id_sted == 0)
			{
			
				$id_sted = $this->input->post('sted_id'); 
			}
		}



		if($aktion == "tilfoej")
		{
			$this->load->model('core/tilfoej_model');
			$this->tilfoej_model->sted_til_begivenhed($id_begivenhed, $id_sted);
		}
		if($aktion == "slet")
		{
			$this->load->model('core/slet_model');
			$this->slet_model->begivenhed_entitet_sted("sted", $id_begivenhed, $id_sted);
		}


		if($vinkel == "sted")
		{	
			redirect("core/vis/se/sted/".$id_sted."/rediger_historie");
		}
		if($vinkel == "begivenhed")
		{	
			redirect("core/vis/se/begivenhed/".$id_begivenhed."/rediger_steder");
		}
		
	}	
	
	/*function begivenhed_entitet()
	{
	
	
		$id_begivenhed = $this->uri->segment(5,0);
		$aktion = $this->uri->segment(4,0);
		$id_sted = $this->uri->segment(6,0);
		if($id_sted == 0)
		{
			
			$id_sted = $this->input->post('sted_id'); 
		}
		//echo "id_begivenhed er ".$id_begivenhed."<br>";
		//echo "id_entitet er ".$id_entitet."<br>";

		if($aktion == "tilfoej")
		{
			$this->load->model('core/tilfoej_model');
			$this->tilfoej_model->sted_til_begivenhed($id_begivenhed, $id_sted);
		}
		if($aktion == "slet")
		{
			$this->load->model('core/slet_model');
			$this->slet_model->begivenhed_entitet_sted("sted", $id_begivenhed, $id_sted);
		}


		
	}*/
	
	function basisrelation()
	{
		$relation_titel_id = $this->uri->segment(4,0); 
		$data['meddelse'] = "";
		
		//HENTER DELTAGEROPLSYNINGER
		$username = $this->session->userdata('username'); 
		$data['username']=$username;
		$this->load->model('login_model');
		$data['deltager'] = $this->login_model->get_deltager_data($username);
		$userid = $data['deltager']['id'];

		//HENTER INGAMEOPLYSNINGER XXX SKAL MÅSKE LÆGGES I SESSIONEN.
		$ingame = $this->session->userdata('ingame'); 
		$ingame_id = $ingame['ingame_id'];
		$data['ingame'] = $ingame;	
		
		//HENTER MODELLER
		$this->load->model('all/vis_model');
				
		$aktion = $this->input->post('aktion');
		if($aktion == "ret")
		{
			$data['titel'] = $this->vis_model->relation_titel($relation_titel_id);
			//print_r($data['titel']);
			$this->load->model('all/rediger_model');
			$hvor = $this->input->post('hvor');
			$ny_titel = $this->input->post('ny_titel');
			$this->rediger_model->titel($data['titel']['id'], $ny_titel, $hvor);
			$data['meddelse'] = "Opdateret";
		}
		
		$data['titel'] = $this->vis_model->relation_titel($relation_titel_id); //skal hentes ind igen for at overskrive et evt. redigeret databaseudtræk.
		
		$data['relation'] = $this->vis_model->relation_raekke('entitet',$data['titel']['id_relation']);
		//print_r($data['relation']); echo "<br><br>";
		$data['under_person'] = $this->vis_model->stamdata('entitet',$data['relation']['under_id']);
		//print_r($data['under_person']); echo "<br><br>";
		$data['over_person'] = $this->vis_model->stamdata('entitet',$data['relation']['over_id']);
		//print_r($data['over_person']); echo "<br><br>";
		
		$data['visning'] = "rediger"; //her angives at visning er lig "rediger", i modstæning til hvis visningen skal være "se", det bruges i viewet "relation_titel".
		
		//GENERERER INDHOLD I FORM AF VIEWS		
		$indhold = array();
		$indhold[] = 'all/relation_titel';
		$data['main_content'] = $indhold;
		$this->load->view('template', $data);
	}
	
	function level()
	{
	
		$type = $this->uri->segment(4,0); 
		$data['type'] = $type;
		
	
		$id = $this->uri->segment(5,0); 
		$alder = 50; //alder bliver ikke brugt endnu - men skal være defineret som halvtreds for at det virker (god kode).
		$nyt_level = $this->input->post('nyt_level');
		$this->load->model('rolemaster/level_model');
		$this->level_model->set_level($id, $nyt_level);
		
		redirect("almanak/side/".$id);			
		
	}


	function upload_billede()
	{



		
		//HENTER DELTAGEROPLSYNINGER
		//$deltager = $this->session->userdata('deltager'); 

		//$data['username']= $deltager['username'];
		//$userid = $deltager['userid'];

		// HENTER MODELLEN, DER OPLOADER BILLEDET TO GANGE, I FULD STØRRELSE OG SOM THUMBNAIL
		$this->load->model('upload_model');

		if ($this->input->post('upload'))
		{
			$element_id = $this->input->post('element_id');
			$type = $this->input->post('type');
			$deltager_id = $this->input->post('deltager_id');
			$titel = $this->input->post('titel');
			$billede_id = $this->upload_model->do_upload($deltager_id, $titel);
			$this->upload_model->billede_relation($billede_id, $element_id);
			echo $titel." er blevet oploaded absolut succesfuldt af ";	

		}

		//$data['images'] = $this->upload_model->get_images();

		//$this->load->view('gallery', $data);
		
		//$indhold[] = 'gallery';

		//$data['main_content'] = $indhold;
		//$this->load->view('template',$data);

		redirect("core/vis/se/".$type."/".$element_id);


	}


	function ret_forfatter(){
		
		$id_element = $this->uri->segment(4);
		$type = $this->input->post('type');	
		$ny_forfatter = $this->input->post('deltager_id');	

		$this->side_administrator->ret_forfatter($id_element,$ny_forfatter);
		
		redirect("core/vis/se/".$type."/".$id_element."/rettighed_deling");

	}


    function godkend_element(){

        echo $element = $this->uri->segment(4);
        
	    $data = array
		    (
			    'approved' => 1
		    );
		
	    $this->db->where('id', $element);
	    $this->db->update("element", $data);

        if($this->uri->segment(5) == "gm_dash"){
            redirect("deltager/gm_dash");
        }
        else{
            redirect("core/vis/se/sted/".$element);
        }
    }


    function godkend_beskrivelse(){

    $beskrivelse_id = $this->uri->segment(4);
    $element_type = $this->uri->segment(6);
    $element_id = $this->uri->segment(7);

	$data = array
		(
			'approved' => 1
		);
		
	$this->db->where('id', $beskrivelse_id);
	$this->db->update("beskrivelse", $data);

        if($this->uri->segment(5) == "gm_dash"){
            redirect("deltager/gm_dash");
        }
        else{
            redirect("core/vis/se/".$element_type."/".$element_id."/vis_beskrivelse/".$beskrivelse_id);
        }
    }


	



}


?>
